#include <cstdio>

int gcd( int a, int b )
{
    int rem;
    while ( b )
    {
        rem = a % b;
        a = b;
        b = rem;
    }
    return a;
}

int main( )
{
    int n, a, b, c, d, p, q;
    scanf("%d", &n);
    while ( n-- )
    {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        p = gcd( b, d );
        q = b * d / p;
        a = q / b * a + q / d * c;
        p = gcd( a, q );
        printf("%d %d\n", a / p, q / p);
    }
    return 0;
}
